package com.wch.SpringBootTestDemo.webmagic;






import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;

@SuppressWarnings("all")
public class GgzyPageProcessor implements PageProcessor {

	//private Site site = Site.me().setRetryTimes(3).setSleepTime(100);
	private Site site = Site.me().setDomain("deal.ggzy.gov.cn");

	@Override
	public Site getSite() {
		// TODO Auto-generated method stub
		return site;
	}

	@Override
	public void process(Page page) {
		// TODO Auto-generated method stub
    /*    page.putField("title", page.getHtml().xpath("//div[@class='BlogEntity']/div[@class='BlogTitle']/h1").toString());
        page.putField("content", page.getHtml().$("div.content").all().toString());
        page.putField("tags",page.getHtml().xpath("//div[@class='BlogTags']/a/text()").all());*/
        
       // page.putField("content", page.getHtml().$("div.publicont").toString());

		//这获取到的是字符串一大堆
		String result = page.getHtml().xpath("//body").toString();
	//	JSONObject.toJavaObject(json, clazz);
		System.out.println("-------------------------------------------");
		String result1 = page.getHtml().toString();
		System.out.println("-------------------------------------------");
		String result2 = page.getHtml().xpath("//body").toString().replace("<body>", "").replace("</body>", "").trim();
		JSONObject jsonObject = new JSONObject();
		JSONObject fromObject = jsonObject.fromObject(result2);
		JSONArray recordMap = (JSONArray) fromObject.get("data");
		
		System.out.println("-------------------------------------------");

        page.putField("content",recordMap );

	}

}
